package cn.lirenyi.basic.service.impl;

import cn.lirenyi.basic.mapper.BaseMapper;
import cn.lirenyi.basic.query.BaseQuery;
import cn.lirenyi.basic.service.IBaseService;
import cn.lirenyi.basic.util.PageList;
import cn.lirenyi.org.domain.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> mapper;

    @Override
    public void add(T t) {
        mapper.add(t);
    }

    @Override
    public void del(Long id) {
        mapper.del(id);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public T queryById(Long id) {
        return mapper.queryById(id);
    }

    @Override
    public List<T> queryAll() {
        return mapper.queryAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery tQuery) {
        // 查总条数
        Integer total = mapper.queryCount(tQuery);

        // 查每页的数据
        List<T> rows = mapper.queryData(tQuery);

        return new PageList<>(total,rows);
    }

    @Override
    public void patchDel(Long[] id) {
        mapper.patchDel(id);
    }
}
